package com.mall.web.controller.product;

import com.mall.product.domain.biz.ProProductNewBiz;
import com.mall.product.domain.entity.ProProduct;
import com.mall.product.domain.req.ProProductNewRequest;
import com.mall.product.service.ProProductService;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.mall.common.annotation.Log;
import com.mall.common.enums.BusinessType;
import com.mall.product.domain.entity.ProProductNew;
import com.mall.product.service.ProProductNewService;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.utils.poi.ExcelUtil;
import com.mall.common.core.page.TableDataInfo;

/**
 * 商品新品推荐Controller
 *
 * @author zhonglin
 * @date 2020-05-24
 */
@Controller
@RequestMapping("/product/productNew")
public class ProProductNewController
    extends BaseController {

  private String prefix = "product/productNew";

  @Autowired
  private ProProductNewService proProductNewService;
  @Autowired
  private ProProductService    proProductService;

  @RequiresPermissions("product:productNew:view")
  @GetMapping()
  public String productNew() {

    return prefix + "/productNew";
  }

  /**
   * 查询商品新品推荐列表
   */
  @RequiresPermissions("product:productNew:list")
  @PostMapping("/list")
  @ResponseBody
  public TableDataInfo list(ProProductNewRequest proProductNew) {

    startPage();
    List<ProProductNewBiz> list = proProductNewService.selectProProductNewList(proProductNew);
    return getDataTable(list);
  }

  /**
   * 导出商品新品推荐列表
   */
  @RequiresPermissions("product:productNew:export")
  @Log(title = "商品新品推荐", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  @ResponseBody
  public AjaxResult export(ProProductNewRequest proProductNew) {

    List<ProProductNewBiz>      list = proProductNewService.selectProProductNewList(proProductNew);
    ExcelUtil<ProProductNewBiz> util = new ExcelUtil<ProProductNewBiz>(ProProductNewBiz.class);
    return util.exportExcel(list, "productNew");
  }

  /**
   * 新增商品新品推荐
   */
  @GetMapping("/add")
  public String add(ModelMap mmap) {

    List<ProProduct> products = proProductService.selectProductAll();
    mmap.put("products", products);

    return prefix + "/add";
  }

  /**
   * 新增保存商品新品推荐
   */
  @RequiresPermissions("product:productNew:add")
  @Log(title = "商品新品推荐", businessType = BusinessType.INSERT)
  @PostMapping("/add")
  @ResponseBody
  public AjaxResult addSave(ProProductNew proProductNew) {

    return toAjax(proProductNewService.insertProProductNew(proProductNew));
  }

  /**
   * 修改商品新品推荐
   */
  @GetMapping("/edit/{productNewId}")
  public String edit(@PathVariable("productNewId") Long productNewId,
                     ModelMap mmap) {

    ProProductNew proProductNew = proProductNewService.selectProProductNewById(productNewId);
    mmap.put("proProductNew", proProductNew);
    return prefix + "/edit";
  }

  /**
   * 修改保存商品新品推荐
   */
  @RequiresPermissions("product:productNew:edit")
  @Log(title = "商品新品推荐", businessType = BusinessType.UPDATE)
  @PostMapping("/edit")
  @ResponseBody
  public AjaxResult editSave(ProProductNew proProductNew) {

    return toAjax(proProductNewService.updateProProductNew(proProductNew));
  }

  /**
   * 删除商品新品推荐
   */
  @RequiresPermissions("product:productNew:remove")
  @Log(title = "商品新品推荐", businessType = BusinessType.DELETE)
  @PostMapping("/remove")
  @ResponseBody
  public AjaxResult remove(String ids) {

    return toAjax(proProductNewService.deleteProProductNewByIds(ids));
  }

}
